package com.example.springboot.controller;
import com.example.springboot.pojo.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.example.springboot.pojo.LocationRecord;
import com.example.springboot.service.LocationRecordService;
import com.example.springboot.pojo.Result;
@RestController
@CrossOrigin
@RequestMapping("/locationRecord")
public class LocationRecordController {
    @Autowired
    private LocationRecordService locationRecordService;
    @PostMapping("/create")
    public Result create(@RequestBody LocationRecord locationRecord)
    {
        locationRecordService.create(locationRecord);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer id)
    {
        locationRecordService.delete(id);
        return Result.success();
    }
    @GetMapping("/findAll")
    public Result findAll()
    {
        List<LocationRecord> locationRecords = locationRecordService.findAll();
        return Result.success(locationRecords);
    }
    @GetMapping("/findByNumber")
    public Result findByNumber (@RequestParam String number)
    {
        List<LocationRecord> locationRecords=locationRecordService.fingByNumber(number);
        return Result.success(locationRecords);
    }
    @GetMapping("/findByLocationId")
    public Result findByLocationId(Integer locationId)
    {
        List<LocationRecord> locationRecords=locationRecordService.findByLocationId(locationId);
        return Result.success(locationRecords);
    }
    @GetMapping("/findByUserId")
    public Result findByUserId()
    {
        List<LocationRecord> locationRecords=locationRecordService.findByUserId();
        return Result.success(locationRecords);
    }
    @PostMapping("/update")
    public Result update(@RequestParam Integer id)
    {
        locationRecordService.update(id);
        return Result.success();
    }
    @GetMapping("/selectPage")
    public Result selectPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(locationRecordService.selectPage(pageNum, pageSize));
    }
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        locationRecordService.deleteBatch(ids);
        return Result.success();
    }
    @PostMapping("/updateByAdmin")
    public Result updateByAdmin(@RequestParam Integer id) {
        locationRecordService.updateByAdmin(id);
        return Result.success();
    }

    @PostMapping("/updateByUser")
    public Result updateByUser(@RequestParam Integer id) {
        locationRecordService.updateByUser(id);
        return Result.success();
    }
}
